<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.2">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"eryangz.gitee.io","root":"/","scheme":"Gemini","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":false,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="mqtt代码注册为服务配置 将代码放到指定位置，给文件添加执行权限 1chmod +x xxx.py">
<meta property="og:type" content="article">
<meta property="og:title" content="ubuntu将程序注册为服务(mqtt、odoo)">
<meta property="og:url" content="https://eryangz.gitee.io/20210529/ubuntu%E5%B0%86%E7%A8%8B%E5%BA%8F%E6%B3%A8%E5%86%8C%E4%B8%BA%E6%9C%8D%E5%8A%A1(mqtt%E3%80%81odoo)/index.html">
<meta property="og:site_name" content="二扬">
<meta property="og:description" content="mqtt代码注册为服务配置 将代码放到指定位置，给文件添加执行权限 1chmod +x xxx.py">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-05-29T13:22:56.000Z">
<meta property="article:modified_time" content="2023-05-20T09:47:07.859Z">
<meta property="article:author" content="二扬">
<meta property="article:tag" content="mqtt">
<meta property="article:tag" content="服务配置">
<meta property="article:tag" content="odoo">
<meta property="article:tag" content="ubuntu">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://eryangz.gitee.io/20210529/ubuntu%E5%B0%86%E7%A8%8B%E5%BA%8F%E6%B3%A8%E5%86%8C%E4%B8%BA%E6%9C%8D%E5%8A%A1(mqtt%E3%80%81odoo)/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>ubuntu将程序注册为服务(mqtt、odoo) | 二扬</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">二扬</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">blog</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/about/" rel="section"><i class="fa fa-fw fa-user"></i>关于</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup">
        <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result">
  <div id="no-result">
    <i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>
  </div>
</div>

    </div>
  </div>

</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://eryangz.gitee.io/20210529/ubuntu%E5%B0%86%E7%A8%8B%E5%BA%8F%E6%B3%A8%E5%86%8C%E4%B8%BA%E6%9C%8D%E5%8A%A1(mqtt%E3%80%81odoo)/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="二扬">
      <meta itemprop="description" content="念念不忘, 必有回响">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="二扬">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          ubuntu将程序注册为服务(mqtt、odoo)
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2021-05-29 21:22:56" itemprop="dateCreated datePublished" datetime="2021-05-29T21:22:56+08:00">2021-05-29</time>
            </span>
              <span class="post-meta-item">
                <span class="post-meta-item-icon">
                  <i class="fa fa-calendar-check-o"></i>
                </span>
                <span class="post-meta-item-text">更新于</span>
                <time title="修改时间：2023-05-20 17:47:07" itemprop="dateModified" datetime="2023-05-20T17:47:07+08:00">2023-05-20</time>
              </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mqtt/" itemprop="url" rel="index"><span itemprop="name">mqtt</span></a>
                </span>
                  ，
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/mqtt/odoo/" itemprop="url" rel="index"><span itemprop="name">odoo</span></a>
                </span>
            </span>

          <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>6.3k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>6 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <h2 id="mqtt代码注册为服务配置"><a href="#mqtt代码注册为服务配置" class="headerlink" title="mqtt代码注册为服务配置"></a>mqtt代码注册为服务配置</h2><ul>
<li><p>将代码放到指定位置，给文件添加执行权限</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod +x xxx.py</span><br></pre></td></tr></table></figure>
<span id="more"></span></li>
<li><p>编写注册文件,在目录：/etc/systemd/system 下添加mqtt_test.service</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">vi mqtt_test.service</span><br><span class="line"></span><br><span class="line"># 编写一下内容</span><br><span class="line">[unit]</span><br><span class="line">Description=mqtt_test</span><br><span class="line">After=basic.service</span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line">KillMode=control-group</span><br><span class="line">WorkingDirectory=/home/workplace/mqtt/mqtt_test</span><br><span class="line">ExecStart=/home/workplace/venv/mqttEnv/bin/python3.6 /home/workplace/mqtt/mqtt_test/mqtt_2.py</span><br><span class="line">Restart=on-success</span><br><span class="line">RestartSec=10</span><br><span class="line">[Install]</span><br><span class="line">Alias=mqtt_test</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure></li>
<li><p>给注册文件添加执行权限</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">chmod +x mqtt_test.service</span><br></pre></td></tr></table></figure></li>
<li><p>重载系统服务，将服务设置为开机启动</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">systemctl daemon-reload</span><br><span class="line">systemctl enable mqtt_test.service</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="配置odoo服务"><a href="#配置odoo服务" class="headerlink" title="配置odoo服务"></a>配置odoo服务</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">[Unit]</span><br><span class="line">Description=Odoo14</span><br><span class="line">Requires=postgresql.service</span><br><span class="line">After=network.target postgresql.service</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line">User=odoo</span><br><span class="line">Group=odoo</span><br><span class="line">ExecStart=python37 /home/workplace/odoo14/odoo-bin -c /home/workplace/odoo14/odoo.conf</span><br><span class="line">Restart=on-success</span><br><span class="line">RestartSec=10</span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br></pre></td></tr></table></figure>

<h2 id="service配置文件说明"><a href="#service配置文件说明" class="headerlink" title="service配置文件说明"></a>service配置文件说明</h2><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br></pre></td><td class="code"><pre><span class="line">关于Systemd用到的 .service 配置文件</span><br><span class="line">分为 3 部分，必须包含 [Service] 部分</span><br><span class="line"></span><br><span class="line">[Unit]</span><br><span class="line">Description=&quot;ops-log&quot;</span><br><span class="line"></span><br><span class="line">Description：当前服务的简单描述</span><br><span class="line"></span><br><span class="line">Documentation：指定服务的文档位置</span><br><span class="line"></span><br><span class="line">After：如果 network.target 或 sshd-keygen.service 需要启动，那么 sshd.service 应该在它们之后启动</span><br><span class="line">Before：定义 sshd 应该在哪些服务之前启动</span><br><span class="line">注意：After 和 Before 字段只涉及启动顺序，不涉及依赖关系</span><br><span class="line"></span><br><span class="line">Wants：表示 sshd.service 与 sshd-keygen.service 之间存在&quot;弱依赖&quot;关系，即如果&quot;sshd-keygen.service&quot;启动失败或停止运行，不影响 sshd.service 继续执行</span><br><span class="line">Requires：表示&quot;强依赖&quot;关系，即如果该服务启动失败或异常退出，那么sshd.service 也必须退出</span><br><span class="line">注意：Wants 字段与 Requires 字段只涉及依赖关系，与启动顺序无关，默认情况下是同时启动。</span><br><span class="line"></span><br><span class="line">[Service]</span><br><span class="line">Type=simple</span><br><span class="line">ExecStart=/opt/n9e/ops-log/n9e-ops</span><br><span class="line">WorkingDirectory=/opt/n9e/ops-log</span><br><span class="line"></span><br><span class="line">Restart=always</span><br><span class="line">RestartSecs=1s</span><br><span class="line">SuccessExitStatus=0</span><br><span class="line">LimitNOFILE=65536</span><br><span class="line">StandardOutput=syslog</span><br><span class="line">StandardError=syslog</span><br><span class="line">SyslogIdentifier=n9e-ops</span><br><span class="line"></span><br><span class="line">Type设置进程的启动类型，为 simple, exec, forking, oneshot, dbus, notify, idle 之一</span><br><span class="line"></span><br><span class="line">simple(当设置了 ExecStart、 但是没有设置 Type与 BusName时，这是默认值)，ExecStart= 进程就是该服务的主进程， 并且 systemd 会认为在创建了该服务的主服务进程之后，该服务就已经启动完成。如果此进程需要为系统中的其他进程提供服务， 那么必须在该服务启动之前先建立好通信渠道(例如套接字)， 这样，在创建主服务进程之后、执行主服务进程之前，即可启动后继单元， 从而加快了后继单元的启动速度。即使不能成功调用主服务进程，systemctl start 也不会执行失败</span><br><span class="line">exec 只有在该服务的主服务进程执行完成之后，systemd 才会认为该服务启动完成。 其他后继单元必须一直阻塞到这个时间点之后才能继续启动，如果不能成功调用主服务进程，systemctl start 将会执行失败</span><br><span class="line">forking 当所有通信渠道都已建好、启动亦已成功之后，父进程将会退出，而子进程将作为主服务进程继续运行。systemd 会认为在父进程退出之后，该服务就已经启动完成。同时设置 PIDFile= 选项可以帮助 systemd 准确可靠的定位该服务的主进程， systemd 将会在父进程退出之后 立即开始启动后继单元。</span><br><span class="line">oneshot 只有在该服务的主服务进程退出之后，systemd 才会认为该服务启动完成，才会开始启动后继单元。通常需要设置 RemainAfterExit= 选项， 当 Type与 ExecStart都没有设置时， Type=oneshot 就是默认值</span><br><span class="line">dbus 只有获得 BusName指定的 D-Bus 名称之后，systemd才会认为该服务启动完成，才会开始启动后继单元。 设为此类型相当于隐含的依赖于 dbus.socket 单元。 当设置了 BusName时， 此类型就是默认值</span><br><span class="line">notify 会在启动完成之后通过接口发送通知消息，systemd 将会在启动后继单元之前， 首先确保该进程已经成功的发送了这个消息。如果设为此类型，那么下文的 NotifyAccess= 将只能设为非 none 值。如果未设置 NotifyAccess或者设为none 将会被自动强制修改为 main 。 Type=notify 尚不能与 PrivateNetwork=yes 一起使用</span><br><span class="line">idle 服务进程将会被延迟到所有活动任务都完成之后再执行，避免控制台上的状态信息与shell脚本的输出混杂在一起。 注意：仅可用于改善控制台输出，切勿将其用于不同单元之间的排序工具； 延迟最多不超过5秒， 超时后将无条件的启动服务进程</span><br><span class="line">通常建议在任何可能的情况下使用Type = simple作为长期运行的服务</span><br><span class="line"></span><br><span class="line">ExecStart：在启动此服务时执行的参数的命令</span><br><span class="line"></span><br><span class="line">WorkingDirectory：配置工作目录，使用需保证该目录存在</span><br><span class="line"></span><br><span class="line">Restart：配置在服务进程退出，终止或超时时是否应重新启动服务。</span><br><span class="line"></span><br><span class="line">no（默认值）不会重新启动该服务</span><br><span class="line">on-success服务进程干净地退出时才会重新启动</span><br><span class="line">on-abnormal信号操作超时或触发看门狗超时终止进程时，将重新启动服务</span><br><span class="line">on-abort服务进程因未被指定为干净退出状态的未被捕获信号而退出时，服务才会重新启动</span><br><span class="line">on-watchdog服务的监视程序超时到期时重新启动服务</span><br><span class="line">always服务将重新启动，无论是否干净地退出，信号异常终止或超时</span><br><span class="line">RestartSec：重新启动服务之前的睡眠时间，默认100毫秒，默认时间单位为秒</span><br><span class="line"></span><br><span class="line">SuccessExitStatus：额外定义其他的进程&quot;正常退出&quot;状态，可以设为一系列 以空格分隔的数字退出码或者信号名称，</span><br><span class="line">SuccessExitStatus=1 2 8 SIGKILL表示当进程的退出码是 1, 2, 8 或被 SIGKILL 信号终止时， 都可以视为&quot;正常退出&quot;。多次使用此选项， 将合并多个列表，设为空则清空先前设置的列表</span><br><span class="line"></span><br><span class="line">LimitNOFILE：文件打开数限制</span><br><span class="line">LimitNOFILE=infinity等同于LimitNOFILE=65536</span><br><span class="line"></span><br><span class="line">StandardOutput：设置标准输出</span><br><span class="line">StandardError：设置标准错误</span><br><span class="line">SyslogIdentifier：日志标识符，将进程名称设置为发送到日志系统或内核日志缓冲区的日志行的前缀。默认为已执行进程的进程名称，仅在 StandardOutput或 StandardError设置为 syslog、journal 或 kmsg（或与 +console 组合使用相同设置）时才有用</span><br><span class="line"></span><br><span class="line">RemainAfterExit：布尔值，指定即使退出所有进程，服务是否应被视为活动状态。，默认为否</span><br><span class="line"></span><br><span class="line">GuessMainPID：布尔值，指定systemd是否应该尝试猜测服务的主PID。如果无法可靠地确定它，除非设置了Type = forking且未设置PIDFile =，否则将忽略此选项，默认为是</span><br><span class="line"></span><br><span class="line">PIDFile：引用服务的PID文件的路径， 对于Type =设置为forking的服务，建议使用此选项。 指定的路径通常指向/ run /下面的文件，指定了相对路径则以/ run /为前缀。 服务管理器在启动服务后读取服务主进程的PID，不会写入此处配置的文件。如果服务仍然存在，它将在服务关闭后删除该文件</span><br><span class="line"></span><br><span class="line">BusName：获取此服务可访问的D-Bus总线名称， 对于Type设置为dbus的服务，此选项是必需的</span><br><span class="line"></span><br><span class="line">ExecStartPre：设置在执行 ExecStart= 之前/后执行的命令行，如果设置了多个命令行，将以出现顺序依次执行。如果某个无 “-” 前缀的命令行执行失败， 那么剩余的命令行将不会被继续执行， 同时该单元将变为失败(failed)状态。仅在所有无 “-” 前缀的 ExecStartPre 命令全部执行成功的前提下， 才会继续执行 ExecStart命令。不可将 ExecStartPre用于需要长时间执行的进程，因为所有由 ExecStartPre= 派生的子进程 都会在启动 ExecStart服务进程之前被杀死</span><br><span class="line"></span><br><span class="line">ExecStartPost：仅在 ExecStart中的命令已经全部执行成功之后才会运行， 判断的标准基于 Type选项。注意，如果在服务启动完成之前，任意一个 ExecStartPre, ExecStart, ExecStartPost中无 “-” 前缀的命令执行失败或超时，ExecStopPost= 将会被继续执行，而 ExecStop= 则会被跳过。</span><br><span class="line"></span><br><span class="line">ExecReload：设置当该服务被要求重新载入配置时执行的命令</span><br><span class="line"></span><br><span class="line">ExecStop：设置当该服务被要求停止时所执行的命令行， 执行完此处设置的所有命令行之后，该服务将被视为已经停止。如果未设置此选项，那么当此服务被停止时， 该服务的所有进程都将会根据 KillSignal的设置被立即全部杀死</span><br><span class="line"></span><br><span class="line">ExecStopPost：用于设置在该服务停止之后所执行的命令行，无论服务是否启动成功， 此选项中设置的命令都会在服务停止后被无条件的执行</span><br><span class="line"></span><br><span class="line">TimeoutStartSec=该服务允许的最大启动时长， 守护进程未能在限定的时长内发出&quot;启动完毕&quot;的信号，该服务将被视为启动失败，并被关闭。 默认以秒为单位，设为 “infinity” 则表示永不超时。 当 Type=oneshot 时， 默认值为 “infinity” (永不超时)， 否则默认值等于 DefaultTimeoutStartSec的值</span><br><span class="line"></span><br><span class="line">TimeoutStopSec：</span><br><span class="line"></span><br><span class="line">设置每个 ExecStop的超时时长，其中之一超时则后继的 ExecStop都会被取消，该服务也会被 SIGTERM 信号强制关闭。 服务没有设置 ExecStop，将会立即被 SIGTERM 信号强制关闭</span><br><span class="line">设置该服务自身停止的超时时长。如果超时，那么该服务将会立即被 SIGTERM 信号强制关闭。默认以秒为单位，设为 “infinity” 则表示永不超时。，默认值等于 DefaultTimeoutStartSec的值</span><br><span class="line">TimeoutSec：同时设置 TimeoutStartSec与 TimeoutStopSec</span><br><span class="line"></span><br><span class="line">RuntimeMaxSec：允许服务持续运行的最大时长。服务持续运行超出限制则强制终止并将该服务变为失败(failed)状态。 注意，此选项对 Type=oneshot 类型的服务无效，因为它们会在启动完成后立即终止，默认值为 “infinity” (不限时长)</span><br><span class="line"></span><br><span class="line">WatchdogSec：设置该服务的看门狗(watchdog)的超时时长</span><br><span class="line"></span><br><span class="line">RestartPreventExitStatus：设为一系列以空格分隔的数字退出码或信号名称，当进程的退出码或收到的信号与此处的设置匹配时， 无论 Restart= 选项是如何设置的， 该服务都将无条件的 禁止重新启动</span><br><span class="line"></span><br><span class="line">RestartForceExitStatus：可以设为一系列以空格分隔的数字退出码或信号名称， 当进程的退出码或收到的信号与此处的设置匹配时， 无论 Restart= 是如何设置的，该服务都将无条件的被自动重新启动。 默认值为空，表示完全遵守 Restart= 的设置</span><br><span class="line"></span><br><span class="line">RootDirectoryStartOnly：布尔值。 设为 yes 表示根目录 RootDirectory= 选项 仅对 ExecStart= 中的程序有效， 而对 ExecStartPre=, ExecStartPost=, ExecReload=, ExecStop=, ExecStopPost= 中的程序无效。 默认值 no 表示根目录对所有 Exec*= 系列选项中的程序都有效</span><br><span class="line"></span><br><span class="line">NonBlocking：是否为所有基于套接字启动传递的文件描述符设置非阻塞标记，默认值为 no</span><br><span class="line"></span><br><span class="line">Sockets：设置一个 socket 单元的名称， 表示该服务在启动时应当从它继承套接字文件描述符</span><br><span class="line"></span><br><span class="line">FileDescriptorStoreMax：允许在 systemd 中最多为该服务存储多少个使用 “FDSTORE=1” 消息的文件描述符，默认值为&quot;0&quot;</span><br><span class="line"></span><br><span class="line">USBFunctionDescriptors：包含 USB FunctionFS 描述符的文件路径，仅与配置了 ListenUSBFunction= 的 socket 单元一起使用，文件内容将被写入 ep0 文件</span><br><span class="line"></span><br><span class="line">USBFunctionStrings：包含 USB FunctionFS 字符串的文件路径</span><br><span class="line"></span><br><span class="line">[Install]</span><br><span class="line">WantedBy=multi-user.target</span><br><span class="line"></span><br><span class="line">multi-user.target为默认target</span><br><span class="line">WantedBy：值是一个或多个 Target，当前 Unit 激活时，符号链接会放入/etc/systemd/system目录下面以 Target 名 + .wants后缀构成的子目录中</span><br><span class="line">RequiredBy：值是一个或多个 Target，当前 Unit 激活时，符号链接会放入/etc/systemd/system目录下面以 Target 名 + .required后缀构成的子目录中</span><br><span class="line">Alias：当前 Unit 可用于启动的别名</span><br><span class="line">Also：当前 Unit 激活（enable）时，会被同时激活的其他 Unit</span><br><span class="line"></span><br></pre></td></tr></table></figure>


    </div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>二扬
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://eryangz.gitee.io/20210529/ubuntu%E5%B0%86%E7%A8%8B%E5%BA%8F%E6%B3%A8%E5%86%8C%E4%B8%BA%E6%9C%8D%E5%8A%A1(mqtt%E3%80%81odoo)/" title="ubuntu将程序注册为服务(mqtt、odoo)">https://eryangz.gitee.io/20210529/ubuntu将程序注册为服务(mqtt、odoo)/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/mqtt/" rel="tag"><i class="fa fa-tag"></i> mqtt</a>
              <a href="/tags/%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE/" rel="tag"><i class="fa fa-tag"></i> 服务配置</a>
              <a href="/tags/odoo/" rel="tag"><i class="fa fa-tag"></i> odoo</a>
              <a href="/tags/ubuntu/" rel="tag"><i class="fa fa-tag"></i> ubuntu</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/20210513/odoo%E5%9F%BA%E7%A1%80%E6%96%B9%E6%B3%95/" rel="prev" title="odoo基础方法">
      <i class="fa fa-chevron-left"></i> odoo基础方法
    </a></div>
      <div class="post-nav-item">
    <a href="/20210529/mqtt%E6%9C%8D%E5%8A%A1%E5%99%A8%E6%90%AD%E5%BB%BA(emqx)/" rel="next" title="mqtt服务器搭建(emqx)">
      mqtt服务器搭建(emqx) <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#mqtt%E4%BB%A3%E7%A0%81%E6%B3%A8%E5%86%8C%E4%B8%BA%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE"><span class="nav-text">mqtt代码注册为服务配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E9%85%8D%E7%BD%AEodoo%E6%9C%8D%E5%8A%A1"><span class="nav-text">配置odoo服务</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#service%E9%85%8D%E7%BD%AE%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E"><span class="nav-text">service配置文件说明</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="二扬"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">二扬</p>
  <div class="site-description" itemprop="description">念念不忘, 必有回响</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">26</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">14</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">27</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/EryangZzz" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;EryangZzz" rel="noopener" target="_blank"><i class="fa fa-fw fa-github"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="https://gitee.com/" title="Gitee → https:&#x2F;&#x2F;gitee.com&#x2F;" rel="noopener" target="_blank"><i class="fa fa-fw fa-github-alt"></i>Gitee</a>
      </span>
      <span class="links-of-author-item">
        <a href="/1289256052" title="QQ → 1289256052"><i class="fa fa-fw fa-qq"></i>QQ</a>
      </span>
      <span class="links-of-author-item">
        <a href="/1289256052@qq.com" title="E-Mail → 1289256052@qq.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
<div class="widget-wrap">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=330 height=110 src="//music.163.com/outchain/player?type=0&id=8435349308&auto=1&height=66"></iframe>
    <h3 class="widget-title">标签云</h3>
    <div id="myCanvasContainer" class="widget tagcloud">
        <canvas width="250" height="250" id="resCanvas" style="width=100%">
            <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/emqx/" rel="tag">emqx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/flask/" rel="tag">flask</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/git/" rel="tag">git</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/js/" rel="tag">js</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/metaclass/" rel="tag">metaclass</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mqtt/" rel="tag">mqtt</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/odoo/" rel="tag">odoo</a><span class="tag-list-count">10</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/odoo%E5%89%8D%E7%AB%AF/" rel="tag">odoo前端</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/odoo%E9%83%A8%E7%BD%B2/" rel="tag">odoo部署</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/office%E9%A2%84%E8%A7%88/" rel="tag">office预览</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pgsql/" rel="tag">pgsql</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pip%E6%BA%90/" rel="tag">pip源</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/pyinstaller/" rel="tag">pyinstaller</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/re/" rel="tag">re</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/rtsp/" rel="tag">rtsp</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/time%E6%A8%A1%E5%9D%97/" rel="tag">time模块</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ubuntu/" rel="tag">ubuntu</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ubuntu%E6%BA%90/" rel="tag">ubuntu源</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%85%83%E7%B1%BB/" rel="tag">元类</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%A4%9A%E7%BA%BF%E7%A8%8B/" rel="tag">多线程</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%8D%E5%8A%A1%E9%85%8D%E7%BD%AE/" rel="tag">服务配置</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/" rel="tag">正则表达式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%AC%91%E8%84%B8%E4%BA%A4%E4%BA%92/" rel="tag">笑脸交互</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%A7%86%E9%A2%91%E6%B5%81/" rel="tag">视频流</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">设计模式</a><span class="tag-list-count">1</span></li></ul>
        </canvas>
    </div>
</div>




      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">二扬</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">105k</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span class="post-meta-item-text">站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">1:35</span>
</div>



        








      </div>
    </footer>
  </div>

  
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
 var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>





  
<script src="/js/local-search.js"></script>













  

  

</body>
</html>
